:root {
  --bg-0: #0d0d0d;
  --bg-1: #121212;
  --bg-2: #181818;
  --bg-3: #242424;
  --accent: #1db954;
  --accent-hover: #1ed760;
  --text-0: #ffffff;
  --text-1: #b3b3b3;
  --text-2: #727272;
  --border: #2a2a2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: 300px;
  min-width: 220px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 18px;
  font-weight: 700;
}

.search-box {
  padding: 0 14px 10px;
}

.search-box input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-0);
  font-size: 13px;
  outline: none;
}
.search-box input:focus {
  border-color: var(--accent);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px 20px;
}

.tree-node { user-select: none; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-1);
  white-space: nowrap;
}

.tree-row:hover { background: var(--bg-3); color: var(--text-0); }
.tree-row.active { background: var(--bg-3); color: var(--accent); font-weight: 600; }

.tree-row .caret {
  width: 12px;
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-2);
  font-size: 10px;
}
.tree-row .caret.open { transform: rotate(90deg); }

.tree-children {
  margin-left: 14px;
  border-left: 1px solid var(--border);
  padding-left: 6px;
}

.tree-children.collapsed { display: none; }

.folder-icon {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}
.folder-icon::before { content: "📁"; margin-right: 2px; }
.folder-icon.open::before { content: "📂"; margin-right: 2px; }
.count-badge {
  margin-left: auto;
  color: var(--text-2);
  font-size: 11px;
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 28px 40px;
  background: linear-gradient(180deg, #1f1f1f 0%, var(--bg-0) 300px);
}

.main-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.main-header h1 {
  font-size: 26px;
  margin: 0;
}

.track-count {
  color: var(--text-1);
  font-size: 13px;
}

.options-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.options-btn:hover {
  background: var(--bg-2, #2a2a2a);
}

.options-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-0, #eee);
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-1, #242424);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-1);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-0, #eee);
}

.modal-body {
  padding: 16px;
}

.track-list-wrap {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  position: relative;
}

table.track-list {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.track-list thead th {
  text-align: left;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-0);
  overflow: hidden;
  white-space: nowrap;
  z-index: 1;
}

.col-idx { width: 44px; text-align: center !important; }
.col-content { color: var(--text-2); }
.col-path { color: var(--text-2); }
.col-download { width: 36px; }

.download-cell { text-align: center; }

.row-download-btn {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
}

.row-download-btn:hover {
  background: var(--bg-2, rgba(255, 255, 255, 0.08));
  color: var(--text-1, #fff);
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
}

.col-resizer:hover,
.col-resizer.resizing {
  background: var(--accent);
  opacity: 0.5;
}

.track-row {
  cursor: pointer;
  border-radius: 4px;
}

.track-row td {
  height: 36px;
  box-sizing: border-box;
  padding: 0 10px;
  line-height: 36px;
  font-size: 13.5px;
  color: var(--text-1);
  border-bottom: 1px solid transparent;
}

.spacer-row td {
  padding: 0;
  border: none;
  line-height: 0;
}

.track-row:hover { background: var(--bg-3); }
.track-row.playing td { color: var(--accent); }
.track-row .idx { text-align: center; color: var(--text-2); }
.track-row.playing .idx::before { content: "▶"; color: var(--accent); }
.track-row .title-cell { color: var(--text-0); }
.track-row.playing .title-cell { color: var(--accent); }
.track-row .title-cell,
.track-row .content-cell,
.track-row .path-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.track-row .content-cell {
  font-size: 12.5px;
  color: var(--text-1);
}
.track-row .path-cell {
  font-size: 12px;
  color: var(--text-2);
}

.empty-msg {
  color: var(--text-2);
  padding: 30px 10px;
  text-align: center;
}

/* Player bar */
.player-bar {
  height: 90px;
  flex-shrink: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 20px;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 280px;
  min-width: 180px;
  overflow: hidden;
}

.now-playing-art {
  width: 48px;
  height: 48px;
  background: var(--bg-3);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.now-playing-info { overflow: hidden; }
.now-title {
  font-size: 13.5px;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.now-path {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 720px;
  margin: 0 auto;
}

.controls {
  display: flex;
  align-items: center;
  gap: 18px;
}

.ctrl-btn {
  background: none;
  border: none;
  color: var(--text-1);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  position: relative;
}
.ctrl-btn:hover { color: var(--text-0); }
.ctrl-btn.active {
  color: var(--accent);
  background: rgba(29, 185, 84, 0.18);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.ctrl-btn.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.play-btn {
  background: var(--text-0);
  color: #000;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.play-btn:hover { background: var(--accent-hover); transform: scale(1.05); }

.seek-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.time {
  font-size: 11px;
  color: var(--text-2);
  min-width: 36px;
  text-align: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-3);
  flex: 1;
  cursor: pointer;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-0);
  cursor: pointer;
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }

.player-right {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 140px;
  justify-content: flex-end;
}

.vol-icon { font-size: 14px; color: var(--text-1); }

#volume { width: 90px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* Context menu */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  padding: 4px;
  min-width: 180px;
}

.context-menu.hidden {
  display: none;
}

.context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--text-0);
  font-size: 13px;
  cursor: pointer;
}

.context-menu-item:hover {
  background: var(--bg-3);
}

.context-menu-item:disabled {
  color: var(--text-2);
  cursor: not-allowed;
  background: none;
}

/* Mobile menu button (hidden on desktop) */
.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 49;
}

.sidebar-backdrop.hidden {
  display: none !important;
}

/* Responsive layout */
@media (max-width: 768px) {
  .menu-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 320px;
    min-width: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop:not(.hidden) {
    display: block;
  }

  .main {
    padding: 14px 14px 24px;
    width: 100%;
  }

  .main-header h1 {
    font-size: 19px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .track-list-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.track-list {
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
  }

  .col-idx { width: 40px; }
  .col-title { width: 45vw; }
  .col-content { width: 45vw; }
  .col-path { width: 45vw; }

  .track-row td {
    height: 44px;
    line-height: 44px;
  }

  /* Player bar */
  .player-bar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
  }

  .player-left {
    width: 100%;
    order: 1;
  }

  .player-center {
    order: 2;
    width: 100%;
    max-width: none;
  }

  .player-right {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .controls {
    gap: 22px;
  }

  #volume {
    flex: 1;
    max-width: 200px;
  }
}

@media (max-width: 420px) {
  .controls {
    gap: 14px;
  }

  .ctrl-btn {
    font-size: 15px;
  }

  .now-playing-art {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }
}
